home *** CD-ROM | disk | FTP | other *** search
- Path: news.clark.net!not-for-mail
- From: gusty@clark.net (Harlan Messinger)
- Newsgroups: comp.lang.c++
- Subject: Re: question assignment operator in c++
- Date: 6 Mar 1996 23:36:39 GMT
- Organization: Clark Internet Services, Inc., Ellicott City, MD USA
- Message-ID: <4hl7i7$81a@clarknet.clark.net>
- References: <menghua_wang.1.002DB7BE@muccmail.missouri.edu>
- NNTP-Posting-Host: explorer.clark.net
- Mime-Version: 1.0
- Content-Type: TEXT/PLAIN; charset=ISO-8859-1
- Content-Transfer-Encoding: 8bit
- X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
-
- menghua wang (menghua_wang@muccmail.missouri.edu) wrote:
- : I do not why the assignment operator can only be overloaded as a member
- : function in a class such as:
- :
- : class myclass {
- : int i;
- : public:
- : myclass operator= (myclass &A) {
- : i = A.i;
- : return *this;
- : }
- : };
- :
- : Why does not the following frind overloading work?
- :
- : mycalss operator= (myclass &A, myclass &B) {
- : A.i = B.i;
- : return A;
- : }
-
- I believe it's because each class has a default assignment operator as an
- implicit member function. Therefore, if you want to write your own, you
- have to overload the existing implied one, which calls for an explicit
- member function. That, or perhaps there would be inheritance problems.
-
-